﻿namespace MXERP.Infrastructure.Store
{
    public partial class TabState
    {
        public static class Remove
        {
            public record Action(string Url) : IAction;

            public class Handler : ActionHandler<Action>
            {
                public Handler(IStore store) : base(store) { }
                TabState TabState => Store.GetState<TabState>();

                public override Task Handle(Action action, CancellationToken cancellationToken)
                {
                    var tab = TabState.Tabs.FirstOrDefault(x => x.Url == action.Url);
                    if (tab!=null && tab.IsAffix != true)
                    {
                        TabState.Tabs.Remove(tab);
                    }
                    return Task.CompletedTask;
                }
            }
        }
    }
}
